﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RobozzleModel;

public partial class puzzle : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected string ToClientTextState(LevelWithDifficulty level)
    {
        StringEncoder encoder = new StringEncoder();
        encoder.EnqueueBits(0, 3);

        string[] colors, items;
        RobozzleService.EntityToObj(level.Board, out colors, out items);
        for (int i = 0; i < RobozzleService.ROWS; i++)
        {
            for (int j = 0; j < RobozzleService.COLS; j++)
            {
                int tile;
                if (items[i][j] == RobozzleService.ITEM_HOLE)
                    tile = 0;
                else
                {
                    tile = "RGB".IndexOf(colors[i][j]) + 1;
                    if (items[i][j] == RobozzleService.ITEM_STAR)
                        tile += 3;
                }
                encoder.EnqueueBits(tile, 3);
            }
        }
        encoder.EnqueueBits(level.RobotRow, 4);
        encoder.EnqueueBits(level.RobotCol, 4);
        encoder.EnqueueBits(level.RobotDir, 2);
        string result = encoder.AllToString();
        return result;
    }
}
